/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.overall;

import com.inspur.edp.bef.bizentity.GspBizEntityObject;
import com.inspur.edp.bef.bizentity.GspBusinessEntity;
import com.inspur.edp.bef.component.ICompMethod;
import com.inspur.edp.bef.component.ICompParameter;
import com.inspur.edp.bef.component.base.VoidReturnType;
import com.inspur.edp.bef.component.enums.ParameterCollectionType;
import com.inspur.edp.bef.component.enums.ParameterType;
import com.inspur.edp.caf.generator.baseInfo.AnnotationInfo;
import com.inspur.edp.caf.generator.baseInfo.AnnotationType;
import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.compileunit.CompileUnitGeneratorContext;
import com.inspur.edp.cef.designtime.api.IGspCommonField;
import com.inspur.edp.cef.designtime.api.element.GspAssociation;
import com.inspur.edp.cef.designtime.api.element.GspElementObjectType;
import com.inspur.edp.cef.designtime.api.entity.ClassInfo;
import com.inspur.edp.cef.generator.DotNetToJavaStringHelper;
import com.inspur.edp.cef.generator.RefObject;
import com.inspur.edp.cef.generator.common.MetadataAdapter;
import com.inspur.edp.cef.generator.entityGenerator.base.elements.ElementAssoGenerator;
import com.inspur.edp.cef.generator.entityGenerator.entity.elements.EntityElementEnumGenerator;
import com.inspur.edp.das.commonmodel.IGspCommonElement;
import com.inspur.edp.das.commonmodel.IGspCommonModel;
import com.inspur.edp.das.commonmodel.IGspCommonObject;
import com.inspur.edp.udt.designtime.api.entity.UnifiedDataTypeDef;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Objects;

public final class Utils {

  public static final String InterfacePrefix = "I";

  public static String getTypeName(String assemblyName, String typeName) {
    return assemblyName + "." + typeName;
  }

  public static TypeInfo getNativeType(IGspCommonField field, CefGeneratorContext cefGenContext) {
    //DataValidator.CheckForNullReference(field, "field");
    if (field.getIsUdt()) {
      return getUdtType(field.getUdtPkgName(), field.getUdtID(), cefGenContext);
    }

    switch (field.getMDataType()) {
      case String:
      case Text:
        return new TypeInfo(String.class);
      case Boolean:
        return new TypeInfo(Boolean.class);
      case Integer:
        return new TypeInfo(Integer.class);
      case Decimal:
        TypeInfo typeInfo = new TypeInfo(BigDecimal.class);

        return typeInfo;
      case Date:
      case DateTime:
        TypeInfo dateTypeInfo = new TypeInfo(Date.class);
        return dateTypeInfo;
      case Binary:
        TypeInfo binaryTypeInfo = new TypeInfo(byte.class);
        binaryTypeInfo.setArray(true);
        return binaryTypeInfo;
      default:
        throw new RuntimeException("invalid enum values" + field.getMDataType());
    }
  }

  public static TypeInfo getRefElementType(IGspCommonField field, GspAssociation association,
      CefGeneratorContext cefGenContext) {
    if (field.getIsUdt()) {
      return getUdtType(field.getUdtPkgName(), field.getUdtID(), cefGenContext);
    }
    switch (field.getObjectType()) {
      case None:

      case Association:
        return getNativeType(field, cefGenContext);
      //throw new Exception($"暂时不支持关联带出关联类型的字段。");
      case Enum:
        return getRefEnumElementType(field, association, cefGenContext);
      default:
        throw new RuntimeException("未知的对象类型{Convert.ToString(field.getObjectType())}");
    }
  }

//    public static String getSameProjRefElementPropertyName(IGspCommonField field, GspAssociation association, CefGeneratorContext cefGenContext) {
//        if (field.getIsUdt()) {
//            if (cefGenContext.isMetadataExistInCurrentProject(field.getUdtID())) {
//                return getUdtTypeString(field.getUdtPkgName(), field.getUdtID(), cefGenContext);
//            }
//        }
//        boolean currentProj = cefGenContext.isMetadataExistInCurrentProject(association.getRefModelID());
//        switch (field.getObjectType()) {
//            case None:
//                return null;
//            case Association:
//                if (currentProj && field.getIsRefElement()) {
//                    return getRefAssoElementTypeName(association.getRefModelPkgName(), association.getRefModelID(), field.getRefElementId(), cefGenContext);
//                }
//                return null;
//            case Enum:
//                if (currentProj) {
//                    return getRefEnumElementTypeName(association.getRefModelPkgName(), association.getRefModelID(), field.getRefElementId(), cefGenContext);
//                }
//                return null;
//            default:
//                throw new RuntimeException("未知的对象类型" + field.getObjectType());
//        }
//    }

  public static TypeInfo getRefElementPropertyName(IGspCommonField field,
      GspAssociation association, CefGeneratorContext cefGenContext) {
    if (field.getIsUdt()) {
//            if (!cefGenContext.isMetadataExistInCurrentProject(field.getUdtID())) {
      return getUdtType(field.getUdtPkgName(), field.getUdtID(), cefGenContext);
//            }
    }

//        boolean currentProj = cefGenContext.isMetadataExistInCurrentProject(association.getRefModelID());

    switch (field.getObjectType()) {
      case None:
        return getNativeType(field, cefGenContext);
      case Association:
        if (!field.getIsRefElement()) {
          return getNativeType(field, cefGenContext);
        }
//                if (!currentProj) {
        return getRefAssoElementType(association.getRefModelPkgName(), association.getRefModelID(),
            field.getRefElementId(), cefGenContext);
//                }

      case Enum:
//                if (!currentProj) {
        return getRefEnumElementType(field, association, cefGenContext);
//                }
//            return null;
      default:
        throw new RuntimeException("未知的对象类型{Convert.ToString(field.getObjectType())}");
    }
  }

  public static IGspCommonField getRefField(IGspCommonField gspCommonField, GspAssociation parentAssociation, CefGeneratorContext cefGeneratorContext){
    if(gspCommonField.getChildAssociations() != null && gspCommonField.getChildAssociations().size() >0){
      return gspCommonField;
    }
    if(parentAssociation != null){
      IGspCommonModel cm = cefGeneratorContext.<IGspCommonModel>getMetadataContent(parentAssociation.getRefModelPkgName(), parentAssociation.getRefModelID());
      IGspCommonElement element = cm.findElementById(gspCommonField.getRefElementId());
      if(element.getObjectType() == GspElementObjectType.Association){
        if(element.getChildAssociations() != null && element.getChildAssociations().size() > 0){
          return element;
        }
      }
    }
    return null;
  }

//	public static TypeSyntax  getRefElementPropertyTypeSyntax(IGspCommonField field, GspAssociation association, CefGeneratorContext cefGenContext, RefObject<java.lang.Class> propType)
//	{
//		java.lang.Class type = GetDiffProjRefElementPropertyName(field, association, cefGenContext);
//		propType.argvalue = type;
//		if (type != null)
//		{
//			return TypeUtils.getTypeSyntax(type);
//		}
//		String typeStr = GetSameProjRefElementPropertyName(field, association, cefGenContext);
//		if (DotNetToJavaStringHelper.isNullOrEmpty(typeStr) == false)
//		{
//			return TypeUtils.ParseGeneratedSyntax(typeStr);
//		}
//		throw new RuntimeException();
//	}

  // region RefAssoElement
//	private static String getRefAssoElementTypeName(String refEntityPkg, String refEntityID, String refElementID, CefGeneratorContext cefGenContext)
//	{
//		IGspCommonModel cm = cefGenContext.<IGspCommonModel>getMetadataContent(refEntityPkg, refEntityID);
//		var assembly = cm.getEntityAssemblyInfo().getAssemblyName();
//		RefObject<String> tempRef_assembly = new RefObject<String>(assembly);
//		IGspCommonElement element = getRefElement(refEntityID, refElementID, cefGenContext, tempRef_assembly);
//		assembly = tempRef_assembly.argvalue;
//		if (element.getIsUdt())
//		{
//			return GetUdtTypeString(element.getUdtPkgName(), element.getUdtID(), cefGenContext);
//		}
//		String className = ElementAssoGenerator.getName(element);
//		return GetTypeName(assembly, className);
//	}
//
//	private static java.lang.Class  getRefAssoElementType(String refEntityPkg, String refEntityID, String refElementID, CefGeneratorContext cefGenContext)
//	{
//		IGspCommonModel cm = cefGenContext.<IGspCommonModel>getMetadataContent(refEntityPkg, refEntityID);
//		//         var assembly = cm.getEntityAssemblyInfo().getAssemblyName();
//		Assembly assembly = cefGenContext.GetAssemblyByMetadataId(refEntityID);
//
//		var element = cm.FindElementById(refElementID);
//
//		var className = " {cm.getEntityAssemblyInfo().DefaultNamespace}.{ElementAssoGenerator.getName(element)}";
//		if (element.getIsUdt())
//		{
//			return GetUdtType(element.getUdtPkgName(), element.getUdtID(), cefGenContext);
//		}
//		//return cefGenContext.GetType(refEntityID, assembly, className);
//		return assembly.GetType(className);
//	}
  private static TypeInfo getRefAssoElementType(String refEntityPkg, String refEntityID,
      String refElementID, CefGeneratorContext cefGenContext) {
    IGspCommonModel cm = cefGenContext.<IGspCommonModel>getMetadataContent(refEntityPkg,
        refEntityID);

    IGspCommonElement element = cm.findElementById(refElementID);
    if (element.getIsUdt()) {
      return getUdtType(element.getUdtPkgName(), element.getUdtID(), cefGenContext);
    }
    TypeInfo typeInfo = new TypeInfo(ElementAssoGenerator.getName(element));
    typeInfo.setTypePackageName(cm.getEntityAssemblyInfo().getDefaultNamespace());
    return typeInfo;
  }

  //endregion

  //region RefEnumElement
  //private static TypeInfo getRefEnumElementType(String refEntityPkg, String refEntityID, String refElementID, CefGeneratorContext cefGenContext) {
  public static TypeInfo getRefEnumElementType(IGspCommonField field, GspAssociation association,
      CefGeneratorContext cefGenContext) {
    IGspCommonModel cm = cefGenContext.<IGspCommonModel>getMetadataContent(
        association.getRefModelName(), association.getRefModelID());
    IGspCommonElement element = cm.findElementById(field.getRefElementId());

    if (element == null) {
      throw new RuntimeException(
          "关联实体" + cm.getCode() + "中没有找到字段" + field.getCode() + "对应的带出字段，字段id为" + field
              .getRefElementId());
    }
    if (element.getIsUdt()) {
      return getUdtType(element.getUdtPkgName(), element.getUdtID(), cefGenContext);
    }
    if (element.getIsRefElement()) {
      element = (IGspCommonElement) getFinalAssoItem(field, association);
    }
    element.getBelongObject().getBelongModel().getEntityAssemblyInfo().getDefaultNamespace();
    TypeInfo typeInfo = new TypeInfo(EntityElementEnumGenerator.getName(element));
    //typeInfo.setTypePackageName(cm.getEntityAssemblyInfo().getDefaultNamespace());
    typeInfo.setTypePackageName(
        element.getBelongObject().getBelongModel().getEntityAssemblyInfo().getDefaultNamespace());
    return typeInfo;
  }

  private static IGspCommonField getFinalAssoItem(IGspCommonField commonField,
      GspAssociation asso) {
    //根据关联BE ID找到当前BE
    GspBusinessEntity businessEntity = (GspBusinessEntity) MetadataAdapter
        .getMetadata(asso.getRefModelID()).getContent();
    //从Be中根据 字段ID找到当前字段\
    //commonField.getRefElementId()
    IGspCommonElement gspCommonElement = businessEntity
        .findElementById(commonField.getRefElementId());
    IGspCommonField returnField = gspCommonElement;
    //判断当前字段是否是关联
    commonField.getParentAssociation().getBelongElement();
    if (gspCommonElement.getIsRefElement()) {
      returnField = getFinalAssoItem(gspCommonElement, gspCommonElement.getParentAssociation());
    }
    return returnField;
  }

//	private static java.lang.Class  getRefEnumElementType(String refEntityPkg, String refEntityID, String refElementID, CefGeneratorContext cefGenContext)
//	{
//		IGspCommonModel cm = cefGenContext.<IGspCommonModel>getMetadataContent(refEntityPkg, refEntityID);
//
//		Assembly assembly = cefGenContext.GetAssemblyByMetadataId(refEntityID);
//
//		var element = cm.FindElementById(refElementID);
//
//		var className = " {cm.getEntityAssemblyInfo().DefaultNamespace}.{EntityElementEnumGenerator.getName(element)}";
//		if (element.getIsUdt())
//		{
//			return GetUdtType(element.getUdtPkgName(), element.getUdtID(), cefGenContext);
//		}
//		//return cefGenContext.GetType(refEntityID, assembly, className);
//		return assembly.GetType(className);
//	}
//
//	private static String  getRefEnumElementTypeName(String refEntityPkg, String refEntityID, String refElementID, CefGeneratorContext cefGenContext)
//	{
//		IGspCommonModel cm = cefGenContext.<IGspCommonModel>getMetadataContent(refEntityPkg, refEntityID);
//		var assembly = cm.getEntityAssemblyInfo().getAssemblyName();
//		RefObject<String> tempRef_assembly = new RefObject<String>(assembly);
//		IGspCommonElement element = GetRefElement(refEntityID, refElementID, cefGenContext, tempRef_assembly);
//		assembly = tempRef_assembly.argvalue;
//		if (element.getIsUdt())
//		{
//			return getUdtTypeString(element.getUdtPkgName(), element.getUdtID(), cefGenContext);
//		}
//		String className = EntityElementEnumGenerator.getName(element);
//		return getTypeName(assembly, className);
//	}

  private static IGspCommonElement getRefElement(String refEntityID, String refElementID,
      CefGeneratorContext cefGenContext, RefObject<String> nameSpace) {
    IGspCommonModel cm = cefGenContext.<IGspCommonModel>getMetadataContent(null, refEntityID);

    IGspCommonElement element = cm.findElementById(refElementID);
    if (element.getIsRefElement()) {
      return getRefElement(element.getParentAssociation().getRefModelID(),
          element.getRefElementId(), cefGenContext, nameSpace);
    } else {
      nameSpace.argvalue = cm.getEntityAssemblyInfo().getAssemblyName();
      return element;
    }
  }

  //endregion

  //region udtElement
  public static TypeInfo getUdtType(String udtPkg, String udtId,
      CefGeneratorContext cefGenContext) {
    UnifiedDataTypeDef udtDef = cefGenContext.<UnifiedDataTypeDef>getMetadataContent(udtPkg, udtId);
    ClassInfo udtClassInfo = udtDef.getGeneratedEntityClassInfo();

//        TypeInfo typeInfo = new TypeInfo(udtClassInfo.getClassName());
//        typeInfo.setTypePackageName(udtClassInfo.getClassNamespace());
    TypeInfo typeInfo = new TypeInfo(udtClassInfo.getClassName());
    typeInfo.setTypePackageName(udtClassInfo.getClassNamespace());
    typeInfo.setUseFullName(true);
    return typeInfo;
  }
//	public static Class  getUdtType(String udtPkg, String udtId, CefGeneratorContext cefGenContext)
//	{
//		if (cefGenContext.isMetadataExistInCurrentProject(udtId))
//		{
//			return null;
//		}
//
//		var udtDef = cefGenContext.<UnifiedDataTypeDef>getMetadataContent(udtPkg, udtId);
//		Assembly assembly = cefGenContext.GetAssemblyByMetadataId(udtId);
//
//		var className = udtDef.getGeneratedEntityClassInfo().GetClassFullName();
//		if (assembly == null)
//		{
//			GSPMetadata metadata = cefGenContext.getMetadata(null, udtDef.Id);
//
//			throw new RuntimeException("无法获取UdtCode=[{udtDef.getCode()}],UdtName=[{udtDef.Name}],UdtRefPath=[{metadata.RelativePath},udtMetadataName=[{metadata.Header.FileName}]],对应的程序集类：{className}");
//		}
//		//         var assembly = udtDef.getGeneratedEntityClassInfo().AssemblyInfo.getAssemblyName();
//
//		//         return cefGenContext.GetType(udtId, assembly, className);
//		return assembly.GetType(className);
//	}
//
//	public static String  getUdtTypeString(String udtPkg, String udtId, CefGeneratorContext cefGenContext)
//	{
//		if (!cefGenContext.isMetadataExistInCurrentProject(udtId))
//		{
//			return null;
//		}
//		var udtDef = cefGenContext.<UnifiedDataTypeDef>getMetadataContent(udtPkg, udtId);
//		return udtDef.getGeneratedEntityClassInfo().getClassFullName();
//	}
  // endregion

//	public static System.Reflection.PropertyInfo  getProperty(java.lang.Class host, String propName)
//	{
//		var pi = host.GetProperty(propName);
//		if (pi != null)
//		{
//			return pi;
//		}
//
//		for (var baseType : host.GetInterfaces())
//		{
//			if (baseType == IEntityData.class || baseType == ICefData.class || baseType == IChildEntityData.class || baseType == IKey.class)
//			{
//				continue;
//			}
//			pi = baseType.GetProperty(propName);
//			if (pi != null)
//			{
//				return pi;
//			}
//		}
//		return null;
//	}

//	public static java.lang.Class  getPropertyType(java.lang.Class host, String propName)
//	{
//		return GetProperty(host, propName)?.PropertyType;
//	}

  public static ArrayList<TypeInfo> getUdtPropertyTypeList
      (UnifiedDataTypeDef udt, String packageName, String className,
          CefGeneratorContext cefGenContext) {
//        if (cefGenContext.isMetadataExistInCurrentProject(udt.getID())) {
//            return null;
//        }
//        return new java.util.ArrayList<java.lang.Class>(java.util.Arrays.asList(
//                new java.lang.Class[]{
//                        cefGenContext.getAssemblyByMetadataId(udt.getId()).getType(fullClassName)
//                }));
    TypeInfo typeInfo = new TypeInfo(className);
    typeInfo.setTypePackageName(packageName);
    return new ArrayList<TypeInfo>(Arrays.asList(
        new TypeInfo[]{
            typeInfo
        }));

  }

  public static ArrayList<String> getUdtPropertyGenerateTypeList
      (UnifiedDataTypeDef udt, String fullClassName, CefGeneratorContext cefGenContext) {
//        if (!cefGenContext.isMetadataExistInCurrentProject(udt.getId())) {
//            return null;
//        }
    return new ArrayList<String>(Arrays.asList(new String[]{fullClassName}));
  }

  //region TypeSyntax

  public static TypeInfo getRefElementTypeSyntax(CefGeneratorContext cefContext,
      IGspCommonField refElement) {

    String refTypeName = getAssociationTypeName(refElement);
    TypeInfo typeInfo = new TypeInfo(refTypeName);
    typeInfo.setTypePackageName(
        refElement.getBelongObject().getGeneratedEntityClassInfo().getClassNamespace());
    return typeInfo;

//        TypeSyntax assTypeSyntax;
//        var refModel = ((GSPCommonObject) ((refElement.getBelongObject() instanceof GSPCommonObject) ? refElement.getBelongObject() : null)).getBelongModel();
//        if (cefContext.isMetadataExistInCurrentProject(refModel.getID())) {
//            assTypeSyntax = TypeUtils.ParseGeneratedSyntax(GetTypeName(refElement.getBelongObject().getGeneratedEntityClassInfo().getClassNamespace(), refElement.getAssociationTypeName()));
//        } else {
//            // 不同工程
//            Assembly assembly = cefContext.GetAssemblyByMetadataId(refModel.getID());
//
//            var entityType = assembly.GetType(refElement.getBelongObject().getGeneratedEntityClassInfo().getClassFullName());
//            assTypeSyntax = TypeUtils.getTypeSyntax(Utils.GetPropertyType(entityType, refElement.getLabelID()));
//        }
//        return assTypeSyntax;
  }

  public static String getAssociationTypeName(IGspCommonField element) {
    return element instanceof IGspCommonElement
        ? ((IGspCommonElement) element).getAssociationTypeName()
        : element.getLabelID() + "Info";
  }

  public static TypeInfo getDbeElementTypeSyntax(CefGeneratorContext cefContext,
      IGspCommonField element, GspElementObjectType objectType) {
//        TypeSyntax assTypeSyntax;
//        // 来源dbe的字段

    GspBusinessEntity be = (GspBusinessEntity) (
        (cefContext.getMetadata().getContent() instanceof GspBusinessEntity) ? cefContext
            .getMetadata().getContent() : null);

    GspBusinessEntity dbe = cefContext.<GspBusinessEntity>getMetadataContent(
        be.getDependentEntityPackageName(), be.getDependentEntityId());
    if (dbe == null) {
      throw new RuntimeException("当前业务实体依赖的业务实体不存在，id={be.DependentEntityId}");
    }
    IGspCommonObject tempVar = dbe.findObjectByCode(element.getBelongObject().getCode());

    GspBizEntityObject refObj = (GspBizEntityObject) ((tempVar instanceof GspBizEntityObject)
        ? tempVar : null);

    IGspCommonElement refElement = refObj.getElementByLabelId(element.getLabelID());

    String typeName = getDbeElementTypeName(refElement, objectType);
    TypeInfo typeInfo = new TypeInfo(typeName);
    typeInfo.setTypePackageName(refObj.getGeneratedEntityClassInfo().getClassNamespace());
    return typeInfo;

//        // 同工程，dbe上对应节点的类名拼上字段类名
//        if (cefContext.IsMetadataExistInCurrentProject(be.DependentEntityId)) {
//            assTypeSyntax = TypeUtils.ParseGeneratedSyntax(GetTypeName(, ));
//        } else {
//            // 不同工程
//            Assembly assembly = cefContext.GetAssemblyByMetadataId(dbe.getID());
//
//            var entityType = assembly.GetType(refObj.getGeneratedEntityClassInfo().GetClassFullName());
//            assTypeSyntax = TypeUtils.getTypeSyntax(Utils.GetPropertyType(entityType, element.getLabelID()));
//        }
//        return assTypeSyntax;
  }

  private static String getDbeElementTypeName(IGspCommonElement field, GspElementObjectType type) {
    switch (type) {
      case Association:
        return field.getAssociationTypeName();
      case Enum:
        return field.getEnumTypeName();
      default:
        throw new RuntimeException("不支持的字段对象类型");
    }
  }

  public static ArrayList<AnnotationInfo> buildOverrideAnnotation() {
    java.util.ArrayList rez = new java.util.ArrayList<AnnotationInfo>();
    rez.add(AnnotationInfo.buildMarker(new TypeInfo("Override")));
    return rez;
  }

  public static TypeInfo createTypeInfo(Class type) {
    return new TypeInfo(type);
//        TypeInfo result = new TypeInfo(type.getName());
//        result.setTypePackageName(type.getPackage().getName());
//        return result;
  }

  public static TypeInfo getReturnType(ICompMethod method, CefGeneratorContext beGenCtx) {
    if (method.getReturnValue() instanceof VoidReturnType) {
      return new TypeInfo("void");
    }
    if (method.getReturnValue().getParameterCollectionType() == ParameterCollectionType.None
        && method.getReturnValue().getParameterTypeEnum() == ParameterType.Custom
        && beGenCtx.getApiGenContext().getPackageName()
        .equals(method.getReturnValue().getAssembly())) {
      return new TypeInfo(method.getReturnValue().getClassName());
    }
    return getNativeType(method.getReturnValue(), beGenCtx.getApiGenContext());
  }

  //不能增加import, 都改成用下面的重载
  @Deprecated
  public static TypeInfo getNativeType(ICompParameter method, CefGeneratorContext beGenCtx) {
    return getNativeType(method, (CompileUnitGeneratorContext)null);
  }

  public static TypeInfo getNativeType(ICompParameter method, CompileUnitGeneratorContext compileUniCtx) {
      java.lang.Class baseType = null;

    TypeInfo result = null;
    switch (method.getParameterTypeEnum()) {
      case Boolean:
        baseType = Boolean.class;
        break;
      case DateTime:
        baseType = java.util.Date.class;
        break;
      case Decimal:
        baseType = java.math.BigDecimal.class;
        if(compileUniCtx != null)
          compileUniCtx.addImport(java.math.BigDecimal.class.getName());
        break;
      case Double:
        baseType = Double.class;
        break;
      case Int32:
        baseType = Integer.class;
        break;
      case Object:
        baseType = Object.class;
        break;
      case String:
        baseType = String.class;
        break;
      case Custom:
        //				if (DotNetToJavaStringHelper.isNullOrEmpty(method.getAssembly()))
        //				{
        //					throw new RuntimeException(/*"BEGen_0001", */formatExceptionMsg("be动作参数的程序集为空"));
        //				}
        if (DotNetToJavaStringHelper.isNullOrEmpty(method.getClassName())) {
          throw new RuntimeException(/*"BEGen_0002", */ "动作参数" + method.getParamName() + "的类名为空");
        }
        result = new TypeInfo(method.getClassName());
        break;
      default:
        throw new RuntimeException();
    }
    if (result == null) {
      result = com.inspur.edp.cef.generator.overall.Utils.createTypeInfo(baseType);
    }

    if(compileUniCtx != null){
      result.addImport(compileUniCtx);
    }

    if (method.getParameterCollectionType() == ParameterCollectionType.Array) {
      result.setArray(true);
    } else if (method.getParameterCollectionType() == ParameterCollectionType.List) {
      String typeName = result.getTypeName();
      result = new TypeInfo(ArrayList.class);
      result.setIsParameterizedType(true);
      result.getArguments().add(new TypeInfo(typeName));
    }
    return result;
  }

  //不能增加import, 都改成用下面的重载
  @Deprecated
  public static ParameterInfo buildParGenInfo(
      ICompParameter compPar, CefGeneratorContext unitCtx, String parName) {
    return buildParGenInfo(compPar, (CompileUnitGeneratorContext)null, parName);
  }

  public static ParameterInfo buildParGenInfo(
      ICompParameter compPar, CompileUnitGeneratorContext unitCtx, String parName) {
    ParameterInfo tempVar = new ParameterInfo();
    tempVar.setParamName((parName != null) ? parName : compPar.getParamCode());
    tempVar.setParamType(getNativeType(compPar, unitCtx));
    return tempVar;
  }

  public static String toUpperCaseFirstOne(String s) {
      if (Character.isUpperCase(s.charAt(0))) {
          return s;
      } else {
          return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0)))
              .append(s.substring(1))
              .toString();
      }
  }

  public static UnifiedDataTypeDef getUdt(IGspCommonField element,
      CefGeneratorContext cefGenContext) {
      if (!element.getIsUdt()) {
          return null;
      }
    UnifiedDataTypeDef udt = cefGenContext
        .getMetadataContent(element.getUdtPkgName(), element.getUdtID());
    Objects.requireNonNull(udt);
    return udt;
  }

  public static String getSetterMethodName(String propertyName){
    return "set".concat(propertyName);
  }

  public static String getGetterMethodName(String propertyName){
    return "get".concat(propertyName);
  }
}
